package com.refuel.repository;

import com.refuel.entity.UserEntity;
import jakarta.persistence.Table;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @author zhanghao
 * @description
 * @date 2024/5/24 10:28
 **/
@Repository
@Table(name = "user")
public interface UserRepository extends JpaRepository<UserEntity, Long> {

    /**
     * 根据uid查询用户信息
     * @param uid 用户id
     * @return 用户信息
     */
    @Query(value = "select * from user where uid =?1", nativeQuery = true)
    UserEntity findByUid(String uid);

    /**
     * 根据uid更新用户信息
     * @param userEntity 用户信息
     */
    @Modifying
    @Query(value = "update user set integral = user.integral, name = user.name, head_url = user.headUrl  where uid = user.uid", nativeQuery = true)
    void updateByUid(@Param("user") UserEntity userEntity);
}
